import { contextBridge, ipcRenderer, shell } from "electron";

contextBridge.exposeInMainWorld("electronAPI", {
  setTitle: title => ipcRenderer.send("title:set", title),
  getCookie: filter => ipcRenderer.invoke("cookie:get", filter),
  setCookie: details => ipcRenderer.invoke("cookie:set", details),
  removeCookie: (url, name) => ipcRenderer.invoke("cookie:remove", url, name),
  clearCookie: url => ipcRenderer.invoke("cookie:clear", url),
  axios: opt => ipcRenderer.invoke("axios", opt),
  useLoading: callback => ipcRenderer.on("screen:loading", callback),
  useMessage: callback => ipcRenderer.on("screen:message", callback),
  createWindow: (hash, opt) => ipcRenderer.invoke("window:create", hash, opt),
  listenBlive: roomId => ipcRenderer.invoke("blive:start", roomId),
  stopBlive: () => ipcRenderer.invoke("blive:stop"),
  addBliveEvent: (name, callback) =>
    ipcRenderer.on(`blive:[${name}]`, callback),
  removeBliveEvent: (name, callback) =>
    ipcRenderer.removeListener(`blive:[${name}]`, callback),
  removeAllEvent: name => ipcRenderer.removeAllListeners(name),
  showOpenDialog: opt => ipcRenderer.invoke("dialog:open", opt),
  readFile: path => ipcRenderer.invoke("file:read", path),
  openExternal: url => ipcRenderer.invoke("shell:open", url),
  getExecArgs: name => ipcRenderer.invoke("args:get", name)
});
